#include "stdafx.h"
#include "KeyString.h"
#include "PakFile.h"

initialiseSingleton(CKeyString);

CKeyString::CKeyString()
{
    HANDLE hFile;
    DWORD dw = 0;
    DWORD dwSize = 0;
    
    m_Datas.clear();

    if (!PAK().OpenFile(c_KeyString, &hFile)) return;   
    dwSize = PAK().GetFileSize(hFile);
    TCHAR* _Buf = new TCHAR[dwSize+1];
    memset(_Buf, 0, dwSize+1);
    PAK().ReadFile(hFile, _Buf, dwSize);
    PAK().CloseFile(hFile);

    CString strData = _Buf+1;
    delete []_Buf;
    CString strItem;
    DWORD dwIndex = 0;
    int iStart = 0;
    while(1)
    {
        strItem = strData.Tokenize(_T("\r\n"), iStart);
        if (iStart==-1) break;
         m_Datas[dwIndex] = strItem;
         dwIndex++;
    }
}

CString CKeyString::GetString(DWORD key)
{
    return m_Datas[key];
}

CStringA CKeyString::GetStrA(DWORD key)
{
    CStringA str(m_Datas[key].GetString());
    return str;
}